﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Ninject;
using Ninject.Modules;
using System.Web.Mvc;
using SeaBattle.Domain.Abstract.Services;
using SeaBattle.Domain.Concrete.Services;
using System.Web.Routing;
using SeaBattle.Domain.Abstract;
using SeaBattle.Domain.Concrete;

namespace UI.Web.Infrastructure
{
    public class NinjectControllerFactory : DefaultControllerFactory
    {
        // A Ninject "kernel" is the thing that can supply object instances
        private IKernel kernel = new StandardKernel(new SportsStoreServices());
        // ASP.NET MVC calls this to get the controller for each request
        protected override IController GetControllerInstance(RequestContext context,
        Type controllerType)
        {
            if (controllerType == null)
                return null;
            return (IController)kernel.Get(controllerType);
        }
        // Configures how abstract service types are mapped to concrete implementations
        private class SportsStoreServices : NinjectModule
        {
            public override void Load()
            {
                Bind<IGameService>().To<FakeGameService>();
                Bind<IPlayerService>().To<FakePlayerService>();
                Bind<IAccountService>().To<FakeAccountService>();
                Bind<IGameRepository>().To<FakeGameRepository>();
            }
        }
    }
}